package com.rd.student.dashuju.wangbo.exercise0728;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class TestStream {

    public static void main(String[] args) throws Exception {
        File file = new File("out.txt");
//        testRead(file);
        testReaddd(file);

    }

    public static void testRead(File file) throws Exception {
        InputStream is = new BufferedInputStream(
                new FileInputStream(file)
        );

        while (true) {
            byte[] bytes = new byte[13];
            int len = is.read(bytes);
            if (len  == -1) {
                break;
            }
            String s = new String(bytes);
            System.out.println(s);
        }
        is.close();
    }

    public static void testReaddd(File file) throws Exception {
        InputStream is = new FileInputStream(file);
        while (true) {
            byte[] bytes = new byte[1024];
            int len = is.read(bytes, 0, bytes.length);
            if ((len = is.read()) == -1) {
                break;
            }
            String s = new String(bytes);
            System.out.println(s);
        }
        is.close();
    }
}
